package com.team1.supervend.domain;

import java.util.ArrayList;
// todo import java.util.Date;

public class PurchaseOrder {
	public ArrayList<SelectedItem> selectedItems = new ArrayList<SelectedItem>();
// todo	private Date date = new Date();
	private boolean isComplete = false;
	float availableMoney;
	
	public PurchaseOrder()
	{
		//System.out.println("Creating PurchaseOrder");
	}
	
	public float getBalance()
	{
		return availableMoney - getTotal().get();
	}
	
	public void becomeComplete() { isComplete = true; }
	
	public boolean isComplete() { return isComplete; }
	
	public void makeSelectedItem( ProductDescription desc, int quantity )
	{
		selectedItems.add( new SelectedItem( desc, quantity ) );
		getTotal();
		getBalance();
		System.out.println("----------------");
		System.out.format("Remaining Balance: $%.2f\n", getBalance());
		System.out.println("----------------");
	}
	
	public PaymentAmount getTotal()
	{
		PaymentAmount total = new PaymentAmount();
		PaymentAmount subtotal = null;
		
		for( SelectedItem selectedItem : selectedItems )
		{
			subtotal = selectedItem.getSubtotal();
			total.add( subtotal );
		}
		return total;
	}
	
	public void addPayment(Money payment){
		availableMoney = payment.get() + availableMoney;
		System.out.format("Available Money $%.2f\n", availableMoney);
	}
	
	public void addPayment(Credit payment){
		availableMoney = payment.get() + availableMoney;
		System.out.format("Available Money $%.2f\n", availableMoney);
	}
}
